package com.zxu.test.base;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.zxu.test.studyapp.R;
import com.zxu.test.util.ActivityUtils;

@SuppressLint("Registered")
public abstract class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        statusBar();
        setContentView(R.layout.activity_base);
        setupViewFragment(getFragment());
    }

    public void restartApp() {
        Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

    public abstract BaseFragment getFragment();

    public abstract void statusBar();

    private void setupViewFragment(BaseFragment baseFragment) {
        BaseFragment fragment = (BaseFragment) getSupportFragmentManager().findFragmentById(R.id.contentFrame);
        if(fragment == null) {
            fragment = baseFragment;
            ActivityUtils.replaceFragmentInActivity(getSupportFragmentManager(), fragment, R.id.contentFrame);
        }
    }


}
